package com.yanqu.road.server.manger.activity.oldplayerreturn;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.oldplayerreturn.*;
import com.yanqu.road.entity.activity.recallplayer.config.RecallPlayerConfig;
import com.yanqu.road.entity.config.vip.VipInfo;
import com.yanqu.road.entity.enums.OldPlayerReturnActivityType;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.log.LogOldPlayerReturn;
import com.yanqu.road.entity.player.ReturnData;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.bussiness.activity.OldPlayerReturnBusiness;
import com.yanqu.road.logic.config.ChannelConfig;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.businessreunion.BusinessReunionActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnActivity;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.VipMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.businessreunion.BusinessReunionActivityMgr;
import com.yanqu.road.server.manger.activity.businessreunion.ReunionConfig;
import com.yanqu.road.server.manger.activity.recallplayer.RecallPlayerMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ：zfr
 * @date ：2021/12/6 11:27
 */
public class OldPlayerReturnMgr extends TempMgr {
    private static OldPlayerReturnActivity activity = new OldPlayerReturnActivity();
    // userId - activityType - data 玩家的回归数据
    private static Map<Long, Map<Integer, OldPlayerReturnUserData>> oldPlayerReturnUserDataMap = new ConcurrentHashMap<>();

    public static OldPlayerReturnActivity getActivity() {
        return activity;
    }

    public static ActivityInfo getActivityInfo() {
        return activity.getActivityInfo();
    }

    //playerId-whiteType 白名单数据
    private static Map<Long, Map<Integer, OldReturnWhite>> whiteMap = new ConcurrentHashMap<>();

    @Override
    public boolean reloadData() throws Exception {
        whiteMap = OldPlayerReturnBusiness.selectOldReturnWhiteMap();
        oldPlayerReturnUserDataMap = OldPlayerReturnBusiness.getUserDataMap();
        return true;
    }

    public static void refreshWhiteMap() {
        try {
            whiteMap = OldPlayerReturnBusiness.selectOldReturnWhiteMap();
        } catch (Exception e) {
            getLogger().error("refresh white map error", e);
        }
    }

    /**
     * 活动重载
     */
    public static void reloadActivityData() {
        getLogger().info("reload oldPlayerReturn activity start");
        // 获取活动
        OldPlayerReturnActivity tempActivity = new OldPlayerReturnActivity();
        ActivityInfo tmpActivityInfo;
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.OldPlayerReturn.getValue());

        if (openActivityInfoList.size() <= 0) {
            getLogger().info("no oldPlayerReturn activity in show time");

            //当前没有活动 将内存的活动信息清空
            tempActivity.clearActivity();
            activity = tempActivity;
            return;
        }

        //只载入最新的活动
        tmpActivityInfo = openActivityInfoList.get(0);
        //事件配置
        Map<Integer, OldPlayerReturnEventConfig> tempEventConfigMap = OldPlayerReturnBusiness.getEventConfigMap(tmpActivityInfo.getActivityId());
        //活动配置
        Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(tmpActivityInfo.getActivityId());
        //每日登录奖励配置
        Map<Integer, List<OldPlayerReturnDayLoginTaskConfig>> loginTaskConfigMap = OldPlayerReturnBusiness.getOldPlayerReturnDayLoginTaskConfigMap(tmpActivityInfo.getActivityId());
        //检查需要的活动配置是不是都有
        int activityType= checkActivityConfig(activityConfigMap, tempEventConfigMap, tmpActivityInfo.getActivityId(), loginTaskConfigMap);
        tempActivity.loadActivity(tmpActivityInfo, tempEventConfigMap, activityConfigMap, loginTaskConfigMap ,activityType);
        activity = tempActivity;

        //同步在线玩家数据
        reloadPlayerData();
        getLogger().info("reload oldPlayerReturn activity end,activityType {}", activityType);
    }

    /**
     * 检查活动配置
     * @param activityConfigMap 配置map
     * @param eventConfigMap 事件配置
     * @param activityId 活动id
     */
    private static int checkActivityConfig(Map<String, ActivityConfig> activityConfigMap, Map<Integer, OldPlayerReturnEventConfig> eventConfigMap, int activityId,Map<Integer,List<OldPlayerReturnDayLoginTaskConfig>> loginTaskConfigMap) {
        List<String> activityConfigParamList = getActivityConfigParamList();
        List<String> newActivityConfigParamList = getNewActivityConfigParamList();
        for (String paramKey : activityConfigParamList) {
            if (!activityConfigMap.containsKey(paramKey)) {
                //没有必需的配置项 就抛异常
                throw new RuntimeException("oldPlayerReturn config param key is no found, paramKey:" + paramKey + ",activityId:" + activityId);
            }
        }
        //vip经验返还配置异常
        if (activityConfigMap.get("RETURN_VIP_EXP_LIMIT").getValue().split("\\|").length != 5 || activityConfigMap.get("RETURN_GOLD_LIMIT").getValue().isEmpty()) {
            throw new RuntimeException("oldPlayerReturn vip return config is error, activityId:" + activityId);
        }

        if (eventConfigMap.size() == 0) { //事件配置没有 理论活动可继续进行 打个log提示
            getLogger().error("oldPlayerReturn eventConfig is null");
        }
        for (String paramKey : newActivityConfigParamList) {
            if (!activityConfigMap.containsKey(paramKey)) {
                //没有必需的配置项 进行老活动
                return OldPlayerReturnActivityType.OLD_ACTIVITY.getValue();
            }
        }
        if (loginTaskConfigMap.isEmpty()) {
            throw new RuntimeException("oldPlayerReturn loginTask reward return config is error, activityId:" + activityId);
        }

        return OldPlayerReturnActivityType.NEW_ACTIVITY.getValue();
    }

    private static List<String> getActivityConfigParamList() {
        List<String> paramList = new ArrayList<>();
        paramList.add("RETURN_OPEN_LIMIT");                 //活动触发条件（身份等级≥|开服天数≤）
        paramList.add("RETURN_VIP_EXP_LIMIT");              //返还VIP经验（返还条件VIP等级≥|返还占比千分比|每日最高返还VIP经验|最低返还天数）
        paramList.add("RETURN_GOLD_LIMIT");                 //返还元宝数量（VIP经验的倍数)
        paramList.add("RETURN_EVENT_REFRESH_TIME");         //事件刷新时间/h
        paramList.add("RETURN_EFFECTIVE_TIME");             //回归持续时间
        return paramList;
    }

    private static List<String> getNewActivityConfigParamList() {
        List<String> paramList = new ArrayList<>();
        paramList.add("RETURN_TASK_OFFLINE_PARAMETER");     //回归任务的离线倍率
        paramList.add("RETURN_TASK_MONTHLY_CARD_FREE_TIME");//月卡免费试用时间/S
        paramList.add("RETURN_MALL_VIP_PARAMETER");         //兑换商店vip兑换次数倍率（参数1≥VIP等级，倍率千分比)
        paramList.add("RETURN_TASK_OFFLINE_PARAMETER_SYSTEM");      //离线倍率（系统商店）
        paramList.add("RETURN_TASK_OFFLINE_PARAMETER_MAX");         //离线倍率最大值(千分比）
        paramList.add("RETURN_DOUBLE_TYPE");                    //condition条件奖励不加倍的类型配置
        paramList.add("RETURN_RESET_DAY");                  //重置回归的天数
        return paramList;
    }

    /**
     * 同步在线玩家
     */
    public static void reloadPlayerData() {
        for (GamePlayer player : GamePlayerMgr.getCopyPlayerMap().values()) {
            player.getModule(OldPlayerReturnModule.class).syncMsg();
        }
    }

    /**
     * 获取当前活动类型的玩家数据
     * @param userId 玩家id
     * @return 玩家回归数据
     */
    public static OldPlayerReturnUserData getUserData(long userId) {
        ActivityInfo activityInfo = getActivityInfo();
        if (!ActivityMgr.activityInTime(activityInfo)) {
            return null;
        }
        Map<Integer, OldPlayerReturnUserData> userDataMap = oldPlayerReturnUserDataMap.get(userId);
        if (userDataMap != null) {
            return userDataMap.get(activityInfo.getType());
        }
        return null;
    }

    /**
     * 活动过期后获取还没有自动发奖的玩家名单
     * @param activityId 活动id
     * @return userDataMap
     */
    public static Map<Long, OldPlayerReturnUserData> getNoSendRewardUserIdMap(int activityId) {
        Map<Long, OldPlayerReturnUserData> userDataMap = new ConcurrentHashMap<>();
        for (Map<Integer, OldPlayerReturnUserData> dataMap : new ArrayList<>(oldPlayerReturnUserDataMap.values())) {
            for (OldPlayerReturnUserData userData : dataMap.values()) {
                //指定活动的玩家 && (是回归玩家且没有自动补发回归任务奖励 || 有绑定的玩家且没有自动补发绑定奖励)
                if (userData.getActivityId() == activityId
                        && ((userData.isReturn() && !userData.isSendReturnConditionRewardState())
                                || userData.isAlreadyBind() && !userData.isSendBindConditionRewardState())) {
                    userDataMap.put(userData.getUserId(), userData);
                }
            }
        }
        return userDataMap;
    }

    /**
     * 新增玩家数据
     * @param data 玩家回归数据
     */
    public static void addUserData(OldPlayerReturnUserData data) {
        synchronized (oldPlayerReturnUserDataMap) {
            if (!oldPlayerReturnUserDataMap.containsKey(data.getUserId())) {
                oldPlayerReturnUserDataMap.put(data.getUserId(), new ConcurrentHashMap<>());
            }
            oldPlayerReturnUserDataMap.get(data.getUserId()).put(data.getActivityType(), data);
        }
    }

    public static void resetReturnState(GamePlayer player) {
        int resetNeedDay = checkCanResetReturnDay();
        synchronized (oldPlayerReturnUserDataMap) {
            boolean canReset = false;
            OldPlayerReturnUserData userData = getUserData(player.getUserId());
            if (userData == null || !userData.isReturn()) {
                return;
            }
            long now = System.currentTimeMillis();
            //先检测一下是否有强制时间点重置
            if (ChannelConfig.FORCE_RESET_RETURN_TIME != 0){
                if ((userData.getReturnTime() < ChannelConfig.FORCE_RESET_RETURN_TIME) && (now >= ChannelConfig.FORCE_RESET_RETURN_TIME)){
                    canReset = true;
                }
            }
            //在检测一下是否可以通过经过时间段来重置
            long timeMillis = now - userData.getReturnTime();
            //回归触发了多久 能否重置
            if (timeMillis / DateHelper.DAY_MILLIONS >= resetNeedDay) {
                canReset = true;
            }
            if (canReset){          //如果可以重置
                if (!checkReturnEffectiveTime(userData.getReturnTime())) {      //先去看看是不是在有效期内
                    if (!userData.isSendReturnConditionRewardState()) {
                        //player.getModule(OldPlayerReturnModule.class).autoSendReturnConditionReward(); 20230316策划说不补发了
                    }
                    //回归重置 要考虑一下 任务重置 自动发奖状态 绑定的新区账号 等等
                    userData.resetReturn();
                    player.getModule(ActivityModule.class).resetReturnTask(getActivityInfo().getActivityId());
                    player.getModule(BusinessReunionActivityModule.class).resetReunionBind();
                }
            }
        }
    }

    private static int checkCanResetReturnDay(){
        int resetStateNeedTime = Integer.MAX_VALUE;
        ReunionConfig config = BusinessReunionActivityMgr.getConfig();
        if (config != null){
            resetStateNeedTime = config.getReturnResetTime();
        }
        if (activity.getActivityType() == OldPlayerReturnActivityType.NEW_ACTIVITY.getValue()){       //新活动有新配置要重置
            ActivityConfig returnResetDay = getActivity().getConfigMap().get("RETURN_RESET_DAY");
            if (returnResetDay != null){
                if (resetStateNeedTime > returnResetDay.getIntValue()){
                    resetStateNeedTime = returnResetDay.getIntValue();
                }
            }
        }

        return resetStateNeedTime;
    }

    /**
     * 玩家回归
     * @param activityId    活动id
     * @param activityType  活动类型
     * @param returnTime    回归时间
     */
    public static void userReturn(long playerId, int activityId, int activityType, long returnTime) {
        synchronized (oldPlayerReturnUserDataMap) {
            OldPlayerReturnUserData userData = OldPlayerReturnMgr.getUserData(playerId);
            boolean needLog = false;
            if (userData == null) {
                OldPlayerReturnUserData tempData = new OldPlayerReturnUserData();
                tempData.setActivityId(activityId);
                tempData.setActivityType(activityType);
                tempData.setUserId(playerId);
                tempData.setReturn(true);
                tempData.setReturnTime(returnTime);
                tempData.setRmbMallLimit(new ConcurrentHashMap<>());
                tempData.setInsertOption();
                OldPlayerReturnMgr.addUserData(tempData);
                needLog = true;
            } else {
                if (!userData.isReturn()) { //已经回归了就不要更新回归状态和时间
                    userData.setActivityId(activityId);
                    userData.setActivityType(activityType);
                    userData.setReturn(true);
                    userData.setReturnTime(returnTime);
                    needLog = true;
                }
            }
            //日志
            try {
                if (needLog) {
                    AutoLogMgr.add(new LogOldPlayerReturn(
                            playerId,
                            activityId,
                            new Date(returnTime),
                            new Date(Objects.requireNonNull(UserMgr.getUserInfo(playerId)).getLastLoginTime() * DateHelper.SECOND_MILLIONS),
                            false,
                            0,
                            new Date(0)
                    ));
                }
            } catch (Exception e) {
                getLogger().error(e);
            }
        }
    }

    /**
     * 自动发放邮件奖励 (绑定后每日返还的vip经验元宝奖励)
     */
    public static void autoSendBindReward() {
        synchronized (oldPlayerReturnUserDataMap) {
            for (Map<Integer, OldPlayerReturnUserData> dataMap : oldPlayerReturnUserDataMap.values()) {
                OldPlayerReturnUserData data = dataMap.get(eActivityType.OldPlayerReturn.getValue());
                if (data == null) {
                    continue;
                }
                //有绑定 并且 还没返完奖
                if (data.isAlreadyBind() && !data.isSendBindRewardOver()) {

                    //算一下 是绑定的第几天
                    long timeMillis = DateHelper.getTodayZeroTimeStamp() - DateHelper.getZeroTimeStamp(data.getOldTime());
                    int nowDays = (int) (timeMillis / DateHelper.DAY_MILLIONS + 1);

                    //已经发过奖
                    if (data.getSendRewardDays() >= nowDays) {
                        continue;
                    }
                    //需要发的都发了 每天都发
                    for (int needSendRewardDays = data.getSendRewardDays() + 1; needSendRewardDays <= nowDays; needSendRewardDays++) {
                        //计算需要返还的奖励
                        ReturnData returnData = calcTodayBindReward(needSendRewardDays, data);
                        //有没有奖励都给他设置状态
                        data.setSendRewardDays(needSendRewardDays);
                        if (returnData.getParams().size() > 0) {
                            //邮件发奖
                            sendMailReward(data.getUserId(), returnData.getParams().get(0), returnData.getParams().get(1), data.isWhiteBindEffect());
                            if (returnData.getRet() == 1) { //返还完了
                                data.setSendBindRewardOver(true);
                                break;
                            }
                        } else {
                            break;
                        }
                    }
                }
            }
        }
    }

    /**
     * 邮件发奖
     * @param userId    玩家id
     * @param reward    奖励
     * @param leftDays  剩余天数
     * @param whiteBindEffect
     */
    private static void sendMailReward(long userId, String reward, String leftDays, boolean whiteBindEffect) {
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        String language = userInfo != null ? userInfo.getLanguage() : "";
        String mailTitle;
        String mailContent;
        if (whiteBindEffect) {
            mailTitle = MultipleLanguageMgr.getContent(MailManager.OLD_PLAYER_RETURN_NEWWORD_REWARD_TITLE, language);
            mailContent = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.OLD_PLAYER_RETURN_NEWWORD_REWARD_CONTENT, language), leftDays);
        } else {
            mailTitle = MultipleLanguageMgr.getContent(MailManager.OLD_PLAYER_RETURN_BIND_REWARD_TITLE, language);
            mailContent = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.OLD_PLAYER_RETURN_BIND_REWARD_CONTENT, language), leftDays);
        }
        MailManager.sendMail(userId, eMailType.SYSTEM.getValue(), reward, mailContent, mailTitle);
    }

    /**
     * 计算今日绑定返还奖励
     * @param userData 玩家数据
     * @return ret param
     */
    public static ReturnData calcTodayBindReward(int nowDays, OldPlayerReturnUserData userData) {
        ReturnData returnData = new ReturnData(0);
        //绑定角色的vip经验
        int bindUserVipLv = VipMgr.getVipLv(userData.getVipExp());

        //绑定时候的返还奖励的配置 记录在玩家身上 活动过期也要继续返还 避免取不到配置
        String returnVipExpLimit = userData.getReturnVipExpConfig();
        if (StringUtils.isNullOrEmpty(returnVipExpLimit)) {
            return returnData;
        }
        String[] split = returnVipExpLimit.split("\\|");
        //绑定的角色vip等级小于 能够返还的最低vip等级配置 不返还
        if (bindUserVipLv < Integer.parseInt(split[0]) && !userData.isWhiteBindEffect()) {
            return returnData;
        }
        //单日返还的vip经验
        int dayReturnVal = 0;

        //需要返回的剩余天数
        long leftDays;
        int maxReturnVipLv = Integer.parseInt(split[4]); //最高返还VIP等级
        int needReturnVipExp;
        int maxVipExp = 0;
        VipInfo vipInfo = VipMgr.getVipInfo(maxReturnVipLv - 1);
        if (vipInfo != null) {
            maxVipExp = (int) vipInfo.getVipExp();

        }
        if (userData.isWhiteBindEffect()) {
            int maxReturnVipExp = BigDecimal.valueOf((double) maxVipExp * Integer.parseInt(split[1]) / 1000)
                    .setScale(0, BigDecimal.ROUND_DOWN).intValue();
            needReturnVipExp = (int) Math.min(maxReturnVipExp, userData.getVipExp());
        } else {
            long vipExpLimitValue = Math.min(maxVipExp, userData.getVipExp()); //最高可计算返还vip经验的上限
            // 总共需要返还的vip经验 向下取整(案子写的)
            needReturnVipExp = BigDecimal.valueOf((double) vipExpLimitValue * Integer.parseInt(split[1]) / 1000)
                    .setScale(0, BigDecimal.ROUND_DOWN).intValue();
        }

        int dayReturnValLimit = Integer.parseInt(split[2]); //每日最高返还经验
        int minReturnDays = Integer.parseInt(split[3]); //最低返还天数
        int diffTotalVipExpVal = dayReturnValLimit * minReturnDays;
        //每日平均返还 返还最低天数
        if (needReturnVipExp <= diffTotalVipExpVal) {
            int averageVal = needReturnVipExp / minReturnDays;
            int leftVal = needReturnVipExp % minReturnDays;
            if (nowDays < minReturnDays) { //平均返还
                dayReturnVal = averageVal;
            } else if (nowDays == minReturnDays) { //最后一天补全
                dayReturnVal = averageVal + leftVal;
                returnData.setRet(1);   //发完了 返回个标识
            }
            leftDays = minReturnDays - nowDays;
        } else { //每日返还最高经验
            //算一下要返多少天
           int needReturnDays = needReturnVipExp / dayReturnValLimit;
            int leftVal = needReturnVipExp % dayReturnValLimit;
            if (leftVal > 0) {
                needReturnDays = needReturnDays + 1;
            }
            if (nowDays < needReturnDays) {  //返还每日最高经验
                dayReturnVal = dayReturnValLimit;
            } else if (nowDays == needReturnDays) { //最后一天补全剩下的
                if (leftVal > 0) {
                    dayReturnVal = leftVal;
                } else {
                    dayReturnVal = dayReturnValLimit;
                }
                returnData.setRet(1);   //发完了 返回个标识
            }
            leftDays = needReturnDays - nowDays;
        }
        if (dayReturnVal > 0) {
            Property returnReward = new Property();
            returnReward.addProperty(GameConfig.GAME_MONEY_VIPEXP_NO_ADD_ACTIVITY, BigInteger.valueOf(dayReturnVal));
            returnReward.addProperty(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(dayReturnVal * Integer.parseInt(split[5])));
            returnData.addParam(PropertyHelper.parsePropertyToString(returnReward));
            returnData.addParam(leftDays + "");
            return returnData;
        }
        return returnData;
    }

    public void repair(long userId, String type) {
        synchronized (oldPlayerReturnUserDataMap) {
            Map<Integer, OldPlayerReturnUserData> userDataMap = oldPlayerReturnUserDataMap.get(userId);
            if (userDataMap == null) {
                return;
            }
            OldPlayerReturnUserData data = userDataMap.get(getActivityInfo().getType());
            if (data == null) {
                return;
            }
        }
    }

    /**
     * 根据openId获取回归角色信息
     * @param openId openId
     * @return userInfoList
     */
    public static GetReturnPlayerInfoRes getReturnPlayerInfo(String openId) {
        if (activity == null) {
            GetReturnPlayerInfoRes res = new GetReturnPlayerInfoRes();
            res.setUserInfoList(new ArrayList<>());
            res.setReturnTime(-1);
            return res;
        }
        return activity.getReturnPlayerInfo(openId);
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean save() {
        for (Map<Integer, OldPlayerReturnUserData> dataMap : new ArrayList<>(oldPlayerReturnUserDataMap.values())) {
            for (OldPlayerReturnUserData data : dataMap.values()) {
                if(null == data.getRmbMallLimit()){
                    data.setRmbMallLimit(new ConcurrentHashMap<>());
                }
                if (data.isInsertOption()) {
                    OldPlayerReturnBusiness.addUserData(data);
                } else if (data.isUpdateOption()) {
                    OldPlayerReturnBusiness.updateUserData(data);
                }
            }
        }
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }


    public static boolean checkOpenServerDays(long registerTime) {
        if (activity == null) {
            return false;
        }
        return activity.checkOpenServerDays(registerTime);
    }

    public static boolean checkReturnEffectiveTime(long returnTime) {
        if (activity == null) {
            return false;
        }
        return activity.checkReturnEffectiveTime(returnTime);
    }

    public static ActivityConfig getActivityConfig(String param) {
        if (activity == null) {
            return null;
        }
        return activity.getActivityConfig(param);
    }

    public static OldPlayerReturnEventConfig getEventConfig(int eventId) {
        if (activity == null) {
            return null;
        }
        return activity.getEventConfig(eventId);
    }

    public static OldPlayerReturnEventConfig randomEvent() {
        if (activity == null) {
            return null;
        }
        return activity.randomEvent();
    }

    public static Map<Integer, OldPlayerReturnEventConfig> getEventConfigMap() {
        if (activity == null) {
            return new ConcurrentHashMap<>();
        }
        return activity.getEventConfigMap();
    }

    public static int crossBindPlayer(long playerId, long oriServerId, long oriUserId, String oriOpenId, PlayerProto.PlayerBaseTempMsg oriUserInfo) {
        if (activity == null) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        return activity.crossBindPlayer(playerId, oriServerId, oriUserId, oriOpenId, oriUserInfo);
    }

    public static Map<Integer, OldReturnWhite> getPlayerWhiteMap(long playerId) {
        return whiteMap.get(playerId);
    }

    public static OldReturnWhite getPlayerWhite(long playerId, int type) {
        Map<Integer, OldReturnWhite> playerWhiteMap = getPlayerWhiteMap(playerId);
        if (playerWhiteMap == null) {
            return null;
        }
        return playerWhiteMap.get(type);
    }

    public static boolean checkAcitvityNeedSpecialReward(int conditionType){
        if (activity == null) {
            return false;
        }
        return activity.chickRewardNeedAddition(conditionType);
    }

    public static int getNowActivityType(){
        if (activity == null){
            return OldPlayerReturnActivityType.NO_ACTIVITY.getValue();
        }
        return activity.getActivityType();

    }

    public static void addRmbMallBuyTime(long userId,int mallId,int times){
        OldPlayerReturnUserData userData = getUserData(userId);
        if (userData == null){
            getLogger().error("玩家{}购买老玩家回归现金礼包 mallId{} 增加次数失败",userId,mallId);
            return;
        }
        if (userData.getRmbMallLimit() == null){
            userData.setRmbMallLimit(new ConcurrentHashMap<>());
        }
        Map<Integer, Integer> rmbMallLimit = userData.getRmbMallLimit();
        if (rmbMallLimit.containsKey(mallId)){
            rmbMallLimit.put(mallId,rmbMallLimit.get(mallId)+times);
        }else {
            rmbMallLimit.put(mallId,times);
        }
        userData.setUpdateOption();

    }
}
